package com.tj.jinzao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tj.jinzao.R;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.MessageBean;
import com.tj.jinzao.widgets.RoundedImageView;

import java.util.List;

public class UserInfoAdapter extends Base_Adapter {
    public UserInfoAdapter(Context context, List list, boolean isFirst) {
        super(context, list, isFirst);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.show_pop_user,null);
            viewHolder.avatar=convertView.findViewById(R.id.avatar);
            viewHolder.name=convertView.findViewById(R.id.nickName);
            viewHolder.check=convertView.findViewById(R.id.check);
            viewHolder.content_lay=convertView.findViewById(R.id.content_lay);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        MessageBean messageBean= (MessageBean) getItem(position);
        if(messageBean!=null){
            if(messageBean.getUser().getAvatar()!=null&&!messageBean.getUser().getAvatar().equals("")){
                Glide.with(context).load(Constant.IMAGE_PREFIX + messageBean.getUser().getAvatar()).into(viewHolder.avatar);
            }else {
                viewHolder.avatar.setImageResource(R.mipmap.default_head_women);
            }
            if(messageBean.getUser().getNickName()!=null){
                viewHolder.name.setText(messageBean.getUser().getNickName());
            }else {
                viewHolder.name.setText("");
            }
            if(messageBean.getUser().isConnect()){
                viewHolder.check.setText("已连接");
            }else {
                viewHolder.check.setText("未连接");
            }


        }
        return convertView;
    }
    class ViewHolder{
        TextView name, nickName;
        RoundedImageView avatar;
        TextView check;
        LinearLayout content_lay;

    }
}
